using UnityEngine;
using UnityEngine.EventSystems;

namespace HerenityCode.Tool
{
    namespace UITools
    {
        /// <summary>
        /// 窗口拖动,挂载在拖动区域上
        /// </summary>
        public class PanelMoveController : MonoBehaviour, IDragHandler, IPointerDownHandler
        {
            public RectTransform panel;

            float offsetX;
            float offsetY;

            public void OnDrag(PointerEventData eventData)
            {
                Vector3 mosPos = Input.mousePosition;
                panel.transform.position = new Vector3(mosPos.x + offsetX, mosPos.y + offsetY);
            }

            public void OnPointerDown(PointerEventData eventData)
            {
                Vector3 mosPos = Input.mousePosition;
                offsetX = panel.transform.position.x - mosPos.x;
                offsetY = panel.transform.position.y - mosPos.y;
            }
        }
    }
}
